package com.itheima.controller;


import com.alibaba.dubbo.config.annotation.Reference;
import com.itheima.entity.PageResult;
import com.itheima.entity.QueryPageBean;
import com.itheima.entity.Result;
import com.itheima.pojo.OrderSettingList;
import com.itheima.service.OrderSettingListService;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 预约列表控制器
 */
@RestController
@RequestMapping("/orderSettingList")
public class OrderSettingListController {

    /**
     * 跨服务器调用接口
     */
    @Reference
    private OrderSettingListService orderSettingListService;

    /**
     * 按条件分页查询
     * @param queryPageBean
     * @return
     */
    @RequestMapping("/findPage")
    public PageResult findPage(@RequestBody QueryPageBean queryPageBean){
        PageResult pageResult = orderSettingListService.findPage(queryPageBean);
        return pageResult;
    }

    /**
     * 添加预约列表
     * @param orderSettingList
     * @return
     */
    @RequestMapping("/addOrderSettingList")
    public Result addOrderSettingList(@RequestBody OrderSettingList orderSettingList){
        try {
            orderSettingListService.addOrderSettingList(orderSettingList);
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false,"添加预约列表失败");
        }
        return new Result(true,"添加预约列表成功");
    }

    /**
     * 取消预约
     * @param id
     * @return
     */
    @RequestMapping("/delete")
    public Result delete(int id){
        try {
            orderSettingListService.delete(id);
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false,"取消预约失败");
        }
        return new Result(true,"取消预约成功");
    }

    /**
     * 批量取消预约
     * @param orderSettingLists
     * @return
     */
    @RequestMapping("/deletes")
    public Result deletes(@RequestBody List<OrderSettingList> orderSettingLists){
        try {
            orderSettingListService.deletes(orderSettingLists);
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false,"批量取消预约失败");
        }
        return new Result(true,"批量取消预约成功");
    }
}
